<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<%@include file="/quick/include/commonQuery.jsp"%>
<%@ include file="/common/taglibs.jsp" %>
<div id='student_div' align='center'></div>
<br>
<br>
<br>
<div id='parameter_form' align='center' ></div>

<script>
var studentField,studentNoForm;
Ext.onReady(function() {
  studentNoForm = new Ext.form.FormPanel({
	      labelAlign:'right',
	      labelWidth:80,
	      align:'center',
	      title:'学生成绩打印',
	      frame:true, 
	      layout:'table',
	      height:120,
	      width:500,
		  items:[{  xtype:'pairfield',
				    label:'学号',
				    id:'c_student',
				    name:'studentNo',
				    click:click,
				    query:qureyStudent
				  },{xtype:'button',
				     text:'打印',
				     handler:queryScore
				 },{xtype:'button',
				     text:'打印就业成绩单',
				     handler:queryMaskScore
				 }]
  });
    
  studentNoForm.render('student_div');		      
  studentField=studentNoForm.findById('c_student');
});

Ext.onReady(function(){
	var gradeStore=new Ext.data.SimpleStore({
     'fields':['value','text'],
     data:<c:out value="${model.gradeJson}" escapeXml='false' />
	});
	var yearCollegeStore=new Ext.data.SimpleStore({
     'fields':['value','text','group'],
     data:<c:out value="${model.yearCollegeJson}" escapeXml='false' />
	});
	var gradeMajorStore=new Ext.data.SimpleStore({
     'fields':['value','text','grade','refid'],
     data:<c:out value="${model.gradeMajorJson}" escapeXml='false' />
	});

	
    
	var form = new Ext.form.FormPanel({
	      labelAlign:'right',
	      title:'专业成绩打印',
	      labelWidth:80,
	      height:g_height/3,
	      frame:true,
	      width:500,
	      items:[{
            xtype:'combo',   
            fieldLabel:'年级',   
            store: gradeStore,   
            editable: false,   
            hiddenName:'GRADE',   
            id:'_GRADE',   
            displayField:'text',   
            valueField:'value',   
            typeAhead:true,   
            mode: 'local',   
            triggerAction: 'all',   
            emptyText:'请选择',   
            selectOnFocus:true,   
            resizable:true,   
            allowBlank:false,   
            anchor:'90%',
            forceSelection:true           
         },{
            xtype:'combo',   
            fieldLabel:'系',   
            store: yearCollegeStore,   
            editable: false,   
            hiddenName:'YEAR_COLLEGE',   
            id:'_YEAR_COLLEGE',   
            displayField:'text',   
            valueField:'value',   
            typeAhead:true,   
            mode: 'local',   
            triggerAction: 'all',   
            emptyText:'请选择',   
            selectOnFocus:true,   
            resizable:true,   
            allowBlank:false,   
            anchor:'90%',
            forceSelection:true           
         },{
            xtype:'combo',   
            fieldLabel:'专业',   
            store: gradeMajorStore,   
            editable: false,   
            hiddenName:'GRADE_MAJOR',   
            id:'_GRADE_MAJOR',   
            displayField:'text',   
            valueField:'value',   
            typeAhead:true,   
            mode: 'local',   
            triggerAction: 'all',   
            emptyText:'请选择',   
            selectOnFocus:true,   
            resizable:true,   
            allowBlank:false,   
            anchor:'90%',
            forceSelection:true           
         }],
         buttons:[{text:'打印',handler:function(){
           f_print(form);
         }},{xtype:'button',
		     text:'打印就业成绩单',
		     handler:function(){
		        f_print(form,'Y');
		     }
		},{text:'重置',handler:function(){
           form.getForm().reset();
         }}] 
          
	});
	
	form.render('parameter_form');   
   
    var gradeCombo=form.getForm().findField('_GRADE');
    var yearCollegeCombo=form.getForm().findField('_YEAR_COLLEGE');
    var gradeMajorCombo=form.getForm().findField('_GRADE_MAJOR');
    
	 yearCollegeCombo.lastQuery="";
	 gradeMajorStore.lastQuery="";
	 
	 gradeCombo.on('change',function(combo){
	   yearCollegeCombo.reset();
	   gradeMajorCombo.reset();
	 });
	 yearCollegeCombo.on('change',function(combo){
	   gradeMajorCombo.reset();
	 });
	 
	 yearCollegeCombo.on('focus',function(combo){	
	    var grade=gradeCombo.getValue();
	    yearCollegeCombo.store.filterBy(function(r){
	      if(r.get('group')==grade||r.get('group')=='null') return true;
	    }); 
	 });    
	 
	 gradeMajorCombo.on('focus',function(combo){	
	    var grade=gradeCombo.getValue();
	    var refid=yearCollegeCombo.getValue();
	    gradeMajorCombo.store.filterBy(function(r){
	      if((r.get('grade')==grade&&r.get('refid')==refid)||(r.get('grade')=='null'&&r.get('refid')=='null')) return true; 
	    }); 
	 });    
    
   
});


function f_print(form,mask){
  var grade=form.getForm().findField('_GRADE').getValue();
  if(Ext.isEmpty(grade)){
    alert('请选择年级');
    form.getForm().findField('_GRADE').focus();
    return;
  }
  var majorNo=form.getForm().findField('_GRADE_MAJOR').getValue();
  if(Ext.isEmpty(majorNo)){
    alert('请选择专业');
    form.getForm().findField('_GRADE_MAJOR').focus();
    return;
  }

  var nj='GRADE[$]'+grade;
  var zydm='MAJOR_NO[$]'+majorNo;
  var matrix=[['jasper','/web-inf/pages/score/print/batchStudentScore.jasper'],
          ['grade',grade],['majorNo',majorNo],
          ['params',nj],['params',zydm]
        ];
  if(Ext.isEmpty(mask)==false){
      matrix=[['jasper','/web-inf/pages/score/print/batchStudentScore.jasper'],
          ['grade',grade],['majorNo',majorNo],
          ['params',nj],['params',zydm],['mask','Y']
        ];    
  }        
  var form=createForm(g_rootPath+'educational/score/majorScorePrint.html',matrix);
  form.target="_blank";
  form.submit();
}

function queryScore(){
  var studentNo=studentField.getValue();
  
  var matrix=[['jasper','/web-inf/pages/score/print/studentScore.jasper'],
        ['params',"XH[$]"+studentNo],['studentNo',studentNo]
        ];
  var form=createForm(g_rootPath+'educational/score/studentScorePrint.html',matrix);
  form.target="_blank";
  form.submit();
}

function queryMaskScore(){
  var studentNo=studentField.getValue();
  
  var matrix=[['jasper','/web-inf/pages/score/print/studentScore.jasper'],
        ['params',"XH[$]"+studentNo],['studentNo',studentNo],['mask','Y']
        ];
  var form=createForm(g_rootPath+'educational/score/studentScorePrint.html',matrix);
  form.target="_blank";
  form.submit();
}


function click(e){
  alert(this.value)
}

function qureyStudent(){
  var sno=this.getValue();
  var pairField=this;
  if(sno==null||sno=="") return;
  Ext.Ajax.request({
    method:'POST',
    url:g_rootPath+'ajax/findStudentByNo.html',
    params:{studentNo:sno},
    success:function(response){
      var resp=Ext.decode(response.responseText);
       if(resp.success){
         pairField.setText(resp.student.studentName);
       }else{
         pairField.setValue('');
         pairField.setText('');
         Ext.Msg.alert('<fmt:message key="label.info"/>',resp.errorInfo);
         
       }
    },
    failure:function(){}
  });
}
</script>
